Ext.define('CS.panel.Pie', {
	extend: 'Ext.chart.Chart',

	textField: undefined,

	countField: undefined,

	animate: true,

	legend: {
		position: 'bottom'
	},

	insetPadding: 30,

	shadow: true,

	constructor: function(config) {
		var me = this;

		config = CS.apply({}, config);

		if (CS.isNull(config.isLoad)) {
			config.isLoad = true;
		}

		var fields = config.fields.split(',');
		config.textField = fields[0];
		config.countField = fields[1];

		config.store = Ext.create('CS.data.CustomStore', {
			url: config.url,
			fields: fields,
			autoLoad: config.isLoad
		});

		config.series = [{
			type: 'pie',
			field: config.countField,
			showInLegend: true,
			donut: false,
			label: {
				field: config.textField,
				display: 'middle',
				contrast: true,
				font: '18px Arial'
			},
			highlight: {
				segment: {
					margin: 20
				}
			},
			tips: {
				trackMouse: true,
				width: 140,
				height: 28,
				renderer: function(storeItem) {
					var total = 0;
					me.store.each(function(rec) {
						total += rec.get(config.countField);
					});
					this.setTitle(Math.round(storeItem.get(config.countField) / total * 100) + '%');
				}
			}
		}];

		me.callParent([config]);
	}

});
